package hardBD;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;


public class AudioLoader {
	File audioFile;
	FileInputStream stream;
	final int second = 44100;
	public AudioLoader(String filename){
		audioFile = new File(filename);
		setupStream();
		byte [] t = loadSample();
		double[] t1 = new double[t.length];
		teardownStream();
		int ct = 0;
		long t2 = System.nanoTime();
		for(byte b : t){
			t1[ct] = t[ct]; 
			ct++;
		}
		long t3 = System.nanoTime();
		System.out.println(t3-t2);
		System.out.println(t.length);
		System.out.println("lt " + t[t.length-1]);
		
		
	}
	
	
	public byte[] loadSample(){
		byte[] result = new byte[second * 10];
		try {
			stream.read(result, 0, result.length); // second * 20
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return result;
	}
	
	public void setupStream(){
		try {
			stream = new FileInputStream(audioFile);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void teardownStream(){
		try {
			stream.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
